{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6fa5f4ba-0f96-4223-96f6-e53ddc38cfe5",
   "metadata": {},
   "source": [
    "<center><img src=\"./image/CLBLOGO.jpg\" alt=\"创乐博\" style=\"width: 300px;\"/></center>\n",
    "\n",
    "# 29.I2C LCD1602液晶显示实验\n",
    "\n",
    "@－－－－湖南创乐博智能科技有限公司－－－－<br>\n",
    "@  文件名：29.I2C LCD1602液晶显示实验.py <br>\n",
    "@  版本：V2.0 <br>\n",
    "@  author: zhulin<br>\n",
    "@  说明：I2C LCD1602液晶显示实验\n",
    "I2C LCD1602液晶显示实验，通过对应的LCD1602液晶显示库函数，进行I2C控制方式，控制LCD1602液晶显示模块显示对应的字符！！！！！！<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "445be920-d473-45b8-8aa6-e4b55af36b2e",
   "metadata": {},
   "source": [
    "## 1.导入必要的库文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ab179391-9c46-48fd-92a4-d95e587c591a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import LCD1602    # LCD1602液晶显示屏库\n",
    "import time"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbee25d9-eeff-4358-8858-030d6724a8f1",
   "metadata": {},
   "source": [
    "## 2.初始化工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8061dfaa-9d83-4472-90c2-1fc60451907a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 初始化LCD1602液晶模块\n",
    "def makerobo_setup():\n",
    "\tLCD1602.makerobo_init(0x27, 1)\t# 初始化(设备地址, 背光设置)\n",
    "\tLCD1602.makerobo_write(0, 0, 'Hello!!!')     # 显示第一行信息\n",
    "\tLCD1602.makerobo_write(0, 1, 'Makerobo kit') # 显示第二行信息\n",
    "\ttime.sleep(2)                       # 延时2S"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e02fbeb2-59db-4f0c-bf5c-78f4e5bd8804",
   "metadata": {},
   "source": [
    "## 3.循环函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e77514af-5ab2-4e49-a633-90fd484dcca2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 循环函数\n",
    "def makerobo_loop():\n",
    "\tmakerobo_space = '                '  # 空显信息\n",
    "\tmakerobo_greetings = 'Thank you for using the makerobo raspberry pi kit! ^_^' # 显示提示信息\n",
    "\tmakerobo_greetings = makerobo_space + makerobo_greetings # 显示信息拼接\n",
    "\t# 无线循环\n",
    "\twhile True:  \n",
    "\t\tmakerobo_tmp = makerobo_greetings                    # 获取到显示信息\n",
    "\t\tfor i in range(0, len(makerobo_greetings)):          # 逐一显示\n",
    "\t\t\tLCD1602.makerobo_write(0, 0, makerobo_tmp)       # 逐个显示\n",
    "\t\t\tmakerobo_tmp = makerobo_tmp[1:]\n",
    "\t\t\ttime.sleep(0.8)                                  # 延时800ms\n",
    "\t\t\tLCD1602.makerobo_clear()                         # 清除显示\n",
    "\n",
    "# 释放资源\n",
    "def destroy():\n",
    "\tpass\t"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39cd4d39-7284-48c4-920c-59969df8900a",
   "metadata": {},
   "source": [
    "## 4.程序入口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a89b2dfd-31a9-4982-9059-42b33115b115",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 程序入口\n",
    "if __name__ == \"__main__\":\n",
    "\ttry:\n",
    "\t\tmakerobo_setup()      # 初始化信息\n",
    "\t\tmakerobo_loop()       # 循环显示信息\n",
    "\texcept KeyboardInterrupt: # 当按下Ctrl+C时，将执行destroy()子程序。\n",
    "\t\tdestroy()             # 释放资源"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
